{% set k = request.args.get('k', '') %}
<nav aria-label="Page navigation">

    {% set k = request.args.k | d('', true) %}

    <div>共{{ pagination.pages }}页，{{ pagination.total }}条数据</div>
    <ul class="pagination">

        {% if pagination.has_prev %}
            <li>
                <a href="{{ url_for(request.endpoint, k = k, p = 1) }}" aria-label="Previous">
                    <span aria-hidden="true">到首页</span>
                </a>
            </li>

            <li>
                <a href="{{ url_for(request.endpoint, k = k, p = pagination.prev_num) }}" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
        {% else %}
            <li class="disabled">
                <a href="" disabled aria-label="Next">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
        {% endif %}

        {% for i in range(4) %}
            {% if pagination.page - loop.revindex > 0 %}
                <li>
                    <a href="{{ url_for(request.endpoint, k = k, p = pagination.page - loop.revindex) }}">
                        {{ pagination.page - loop.revindex }}
                    </a>
                </li>
            {% endif %}
        {% endfor %}

        <li class="active"><a href="#">{{ pagination.page }}</a></li>

        {% for i in range(5) %}
            {% if pagination.page + loop.index <= pagination.pages %}
                <li>
                    <a href="{{ url_for(request.endpoint, k = k, p = pagination.page + loop.index) }}">
                        {{ pagination.page + loop.index }}
                    </a>
                </li>
            {% endif %}
        {% endfor %}

        {#{{ request.args }}#}
        {% if pagination.has_next %}
            <li>
                <a href="{{ url_for(request.endpoint, k = k, p = pagination.next_num) }}" aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>

            <li>
                <a href="{{ url_for(request.endpoint, k = k, p = pagination.pages) }}" aria-label="Previous">
                    <span aria-hidden="true">到末页</span>
                </a>
            </li>

        {% else %}
            <li class="disabled">
                <a href="#" disabled aria-label="Next">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        {% endif %}


    </ul>

</nav>